package cn.itsource.basic.controller;


import cn.itsource.basic.dto.AccountLoginDto;
import cn.itsource.basic.dto.WechatLoginDto;
import cn.itsource.basic.service.ILoginService;
import cn.itsource.basic.util.AjaxResult;
import cn.itsource.user.dto.PhoneRegisterDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;


@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private ILoginService loginService;

    /**
     * 账号登陆
     * @param dto
     * @return
     */
    @PostMapping("/account")
    public AjaxResult accountLogin(@RequestBody @Valid AccountLoginDto dto){

        Map<String, Object> map = loginService.accountLogin(dto);

        return AjaxResult.me().success(map);
    }

    /**
     * 微信登陆
     * @param dto
     * @return
     */
    @PostMapping("/wechat")
    public AjaxResult wechatLogin(@RequestBody WechatLoginDto dto){
        return loginService.wechatLogin(dto);
    }

    /**
     * 微信登陆绑定
     * @param dto
     * @return
     */
    @PostMapping("/wechat/binder")
    public AjaxResult wechatBinder(@RequestBody WechatLoginDto dto){
        Map<String, Object> stringObjectMap = loginService.wechatBinder(dto);
        return AjaxResult.me().success(stringObjectMap);
    }
}
